package datastructure.bitwise;

/**
 * An unsorted array of integers where every integer appears exactly
 * twice, except for one integer which appears only once. Write an algorithm  
 * that finds the integer that appears only once.
 * 
 * @author Lei
 */
public class oddItemOut
{

    public static int oddItemOut(int[] array)
    {
        int value = 0;
        for (int i = 0; i < array.length; i++)
        {
            value ^= array[i];
        }
        return value;
    }

    public static void main(String args[])
    {
        int[] arr = new int[5];
        arr[0] = 1;
        arr[1] = 15;
        arr[2] = 1;
        arr[3] = 16;
        arr[4] = 16;

        System.out.println(oddItemOut.oddItemOut(arr));

    }
}
